package com.rabbitmq.extension.listener;

import com.rabbitmq.client.Channel;
import com.rabbitmq.extension.constant.Constants;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.io.UnsupportedEncodingException;

//@Component
public class QosListener {
    @RabbitListener(queues = Constants.QOS_QUEUE)
    public void ListenerQueue(Message message, Channel channel) throws IOException {
        long deliveryTag=message.getMessageProperties().getDeliveryTag();
        System.out.printf("消费者1接收到信息: %s, deliveryTag: %d%n",new String(message.getBody(),"UTF-8"),deliveryTag);

//        手动签收
        channel.basicAck(deliveryTag,true);
    }
    @RabbitListener(queues = Constants.QOS_QUEUE)
    public void ListenerQueue2(Message message, Channel channel) throws IOException, InterruptedException {
        long deliveryTag=message.getMessageProperties().getDeliveryTag();
        System.out.printf("消费者2接收到信息: %s, deliveryTag: %d%n",new String(message.getBody(),"UTF-8"),deliveryTag);

//        Thread.sleep(100);
//        手动签收
        channel.basicAck(deliveryTag,true);
    }

}
